package com.ztools.pc.provider;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.api.service.pc.PcMemberService;
import com.ztools.common.model.pc.information.InformationPoint;
import com.ztools.common.model.pc.information.InformationSignIn;
import com.ztools.common.model.pc.information.WeChatMember;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.enumUnit.PointChannelEnum;
import com.ztools.pc.service.information.InformationPointService;
import com.ztools.pc.service.information.InformationSignInService;
import com.ztools.pc.service.information.MemberService;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * @Author: seeTools
 * @Date: 2023/4/15  15:23
 * @Version 1.0
 */
@Service(version = "1.0", timeout = 3000)
public class PcMemberServiceImpl implements PcMemberService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private MemberService memberService;
    @Resource
    private InformationSignInService informationSignInService;
    @Resource
    private InformationPointService informationPointService;

    @Override
    public WeChatMember getMemberInfo(String openid) {
        return memberService.findByOpenId(openid);
    }

    @Override
    public boolean checkSing(Long memberId) {
        return informationSignInService.checkSing(memberId);
    }

    @Override
    public boolean signIn(InformationSignIn informationSignIn) {
        InformationPoint informationPoint = InformationPoint.builder()
                .memberId(informationSignIn.getMemberId())
                .channel(PointChannelEnum.SIGN_IN.getChannel())
                .operationPoints(informationSignIn.getAddPoint())
                .remark(PointChannelEnum.SIGN_IN.getName())
                .build();
        informationPointService.increase(informationPoint);
        return informationSignInService.save(informationSignIn);
    }


    @Override
    public Page<InformationPoint> getPointRecord(PageUtil<InformationPoint> pageUtil) {
        return informationPointService.findList(pageUtil);
    }

}
